package chenji.yourticket.editor;

import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;

import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;

public class MaterialManager {
	private final HashMap<Material, MaterialInfo> map = new HashMap<Material, MaterialInfo>();
	private LinkedHashSet<MaterialInfo> tmi = null;

	public double getPrice(Material m) {
		MaterialInfo mi = this.map.get(m);
		if (mi == null) {
			return 0.0D;
		}
		return mi.getPrice();
	}

	public void registerMaterialInfo(Material m, double price) {
		this.map.put(m, new MaterialInfo(new HashSet<Enchantment>(), m, price));
	}

	public void registerMaterialInfo(HashSet<Enchantment> ench, Material m, double price) {
		this.map.put(m, new MaterialInfo(ench, m, price));
	}


	public LinkedHashSet<MaterialInfo> getTreeSet() {
		if (this.tmi == null) {
			this.tmi = new LinkedHashSet<MaterialInfo>();
			for (Material m : this.map.keySet()) {
				this.tmi.add(this.map.get(m));
			}
		}
		return this.tmi;
	}
}
